package pkg

import (
	"database/sql"
	"gorm.io/driver/postgres"
	"gorm.io/gorm"
	"time"
)

var DB *gorm.DB

func init() {
	//数据库连接
	dsn := ""
	ORM, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
		return
	}
	sqlDB, err := ORM.DB()
	if err != nil {
		defer func(sqlDB *sql.DB) {
			err := sqlDB.Close()
			if err != nil {

			}
		}(sqlDB)
		sqlDB.SetMaxIdleConns(10)
		sqlDB.SetMaxOpenConns(100)
		sqlDB.SetConnMaxLifetime(time.Hour)
	}
	DB = ORM
}
